<template>
    <view class="content">
        <view class="loc" @click="show = true">
            <view class="tt">省市区</view>
            <view class="selectx">
                <view class="txt u-line-1">{{ region || '请选择' }}</view>
                <u-icon name="arrow-down-fill" color="#575757" size="18"></u-icon>
            </view>
        </view>
        <view class="itemx" v-for="(item,index) in list" :key="index">
            <view class="top_msg">
                <image :src="item.image_uri_txt" class="pic"></image>
                <view class="msg_ctn">
                    <view class="title u-line-1">{{item.title}}</view>
                    <view class="iden" v-if="item.designation">
                        <view class="zzx">
                            <image src="@/static/icon/tex.png" class="ico"></image>
                        </view>
                        <text class="ttx">{{item.designation}}</text>
                    </view>
                    <view class="sux" v-if="item.describe">
                        <text class="tt">主营业务：</text>{{item.describe}}
                    </view>
                </view>
            </view>
            <view class="locx">
                <view class="txtx">
                    <view class="ctcg" v-if="item.telephone">
                        <image src="@/static/icon/iiix1.png" class="ico"></image>
                        <text class="tzt u-line-1">{{item.telephone}}</text>
                    </view>
                    <view class="ctcg" v-if="item.address">
                        <image src="@/static/icon/iiix2.png" class="ico"></image>
                        <text class="tzt u-line-1">{{item.address}}</text>
                    </view>
                </view>
                <view class="gox" @click="goDetail(item.id)">查看详情</view>
                <image v-if="item.telephone" @click="goTel(item.telephone)" src="@/static/icon/telx.png" class="tel"></image>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
        
        <!-- 省市区 -->
        <u-select v-model="show" mode="mutil-column-auto" :list="regionList" value-name="region_id" label-name="name" child-name="sub" @confirm="confirm"></u-select>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                regionList: [],
                region: '', //省市区
                provinceVal: '',
                cityVal: '',
                areaVal: '',
                show: false,
            };
        },
        onLoad() {
			this.region = '内蒙古自治区/通辽市'
			this.provinceVal = 150000
			this.cityVal = 150500
			
            this.getRegion()
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            goTel(t) {
            	this.$call(t)
            },
			
            goDetail(id) {
                this.$gTo(`/pages/drug/detail?id=${id}`)
            },
            
            // 选择省市区
            confirm(e) {
                console.log(e);
                this.region = e[0].label + '/' + e[1].label + '/'  + e[2].label
                this.provinceVal = e[0].value
                this.cityVal = e[1].value
                this.areaVal = e[2].value
                
                this.page = 1
                this.list = []
                this.status = 'loadmore'
                this.getList()
            },
            
            // 获取省市区
            getRegion(){
            	this.$ajax('region', {
            		
            	}).then(ret => {
            		if (ret.status == 0) {
            			this.regionList = ret.data
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('serviceList', {
                    userToken: this.$getSync('userToken'),
                    page: this.page,
                    limit: 10,
                    type: 1,//类型 1-兽医兽药 其他是服务类型id
                    keywords: '',
                    province: this.provinceVal,
                    city: this.cityVal,
                    district: this.areaVal,
                }).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data && ret.data.list && ret.data.list.length > 0) {
                        	this.list = this.list.concat(ret.data.list);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style scoped lang="scss">
    .content {
        min-height: 100vh;
        background: #f5f5f5;
    }

    .loc {
        position: sticky;
        width: 100%;
        padding: 0 20rpx;
        background: #f5f5f5;
        margin: 0 auto 30rpx;
        display: flex;
        align-items: center;
        left: 0;
        top: 0;
        z-index: 1;

        .tt {
            font-size: 24rpx;
            color: #737373;
            width: 90rpx;
        }

        .selectx {
            flex: 1;
            width: 0;
            height: 64rpx;
            background-color: #fff;
            border-radius: 10rpx;
            align-items: center;
            padding: 0 18rpx;
            display: flex;

            .txt {
                font-size: 24rpx;
                color: #000000;
                padding-right: 16rpx;
                flex: 1;
                width: 0;
            }
        }
    }

    .itemx {
        width: 710rpx;
        margin: 0 auto 20rpx;
        border-radius: 20rpx;
        overflow: hidden;

        .top_msg {
            background: #fff;
            padding: 40rpx 32rpx 28rpx;
            display: flex;

            .pic {
                width: 160rpx;
                height: 160rpx;
                border-radius: 10rpx;
                margin-right: 18rpx;
            }

            .msg_ctn {
                flex: 1;
                width: 0;

                .title {
                    font-size: 28rpx;
                    color: #333;
                    line-height: 46rpx;
                    height: 46rpx;
                }

                .iden {
                    display: flex;
                    width: 156rpx;
                    height: 40rpx;
                    background: #feefef;
                    border-radius: 4rpx;
                    margin-bottom: 12rpx;

                    .zzx {
                        width: 40rpx;
                        height: 40rpx;
                        border: 4rpx 0 0 4rpx;
                        background: linear-gradient(to right, #fe601d, #ff2a25);
                        display: flex;
                        align-items: center;
                        justify-content: center;

                        .ico {
                            width: 13rpx;
                            height: 24rpx;
                            display: block;
                        }
                    }

                    .ttx {
                        font-size: 24rpx;
                        color: #ff2825;
                        text-indent: 6rpx;
                        height: 40rpx;
                        line-height: 40rpx;
                    }
                }

                .sux {
                    font-size: 24rpx;
                    color: #333333;

                    .tt {
                        font-weight: 700;
                    }
                }
            }
        }

        .locx {
            display: flex;
            height: 100rpx;
            background: #f0f2fa;
            align-items: center;
            padding: 0 32rpx;

            .txtx {
                flex: 1;
                width: 0;
                padding-right: 20rpx;

                .ctcg {
                    display: flex;
                    height: 36rpx;
                    align-items: center;

                    .ico {
                        width: 18rpx;
                        height: 26rpx;
                        margin-right: 12rpx;
                    }

                    .tzt {
                        flex: 1;
                        width: 0;
                        font-size: 24rpx;
                        color: #333333;
                    }
                }
            }

            .gox {
                width: 130rpx;
                height: 54rpx;
                border-radius: 100px;
                text-align: center;
                border: 1rpx solid #696b73;
                line-height: 52rpx;
                font-size: 24rpx;
                color: #696b73;
                margin-right: 20rpx;
            }

            .tel {
                width: 54rpx;
                height: 54rpx;
            }
        }
    }
</style>